package com.channel.temperature.collect.app.dao

import android.content.Context
import android.util.Log
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.sqlite.db.SupportSQLiteDatabase
import com.channel.temperature.collect.data.response.OfflineBean

@Database(entities = [OfflineBean::class], version = 2)
abstract class OfflineBase : RoomDatabase() {
    abstract fun offlineDao(): OfflineBeanDao

    companion object {
        private var instance: OfflineBase? = null

        private val TAG: String? = OfflineBase::class.simpleName

        fun get(context: Context): OfflineBase {
            if (instance == null) {
                instance = Room.databaseBuilder(context, OfflineBase::class.java, "offline_.db")
                    .fallbackToDestructiveMigration()

                    //是否允许在主线程进行查询
                    .allowMainThreadQueries()
                    .fallbackToDestructiveMigration()
                    .addCallback(object : Callback() {
                        override fun onCreate(db: SupportSQLiteDatabase) {
                            super.onCreate(db)
                            Log.e(TAG, "onCreate db_name is=" + db.path)
                        }
                    })
                    .build()


            }
            return instance!!
        }


    }

}
